package com.health.httpbean.format;

import android.text.TextUtils;

import com.blankj.utilcode.util.TimeUtils;
import com.health.httpbean.model.FjhBean;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.CD_TUBERCULOSIS_BASEINFO;
import com.health.tablebean.CD_TUBERCULOSIS_FOLLOWUP;
import com.health.viewscontrols.NovaApplication;

import net.tsz.afinal.db.sqlite.DbModel;

import java.util.List;

import static com.health.httpbean.format.FormatUtils.formatAskSymptom;
import static com.health.httpbean.format.FormatUtils.parseInt;
import static com.health.httpbean.format.FormatUtils.parseString;

/**
 * author : xiaoxin
 * date   : 2020/12/17 17:23
 * desc   : 肺结核
 * update :
 */
public class FormatFjhData {

    public static FjhBean formatFjh(CD_TUBERCULOSIS_FOLLOWUP table, List<BD_DD_INFO> listZZs) {
        FjhBean bean = new FjhBean();

        try {
            bean.CardID = table.getCARDID();
//            bean.ID_UserDocument = table.getPERSONALID();
            String userSql = "SELECT * FROM ARCHIVE_BASEINFO WHERE IDCARD = '" + table.getCARDID() + "'";
            DbModel userModel = NovaApplication.fdbmanger.findDbSql(userSql);
            bean.UserName = userModel.getString("CUSTOMERNAME");
            bean.BianHao = table.getPERSONALID();
            try {
                bean.SuiFangRiQi = TimeUtils.millis2String(
                        table.getHAPPENTIME().getTime(), "yyyy-MM-dd");
            } catch (Exception e) {
                e.printStackTrace();
            }

            bean.ZhuanZhenYuanYin = table.getTRANSFER_REASON();
            //有无转诊   DM01-11_2 有 DM01-11_1 无
            if (!TextUtils.isEmpty(table.getTRANSFER_REGION())) {
                bean.ZhuanZhenQingKuang = 2;
            }else {
                bean.ZhuanZhenQingKuang = 1;
            }
            bean.ZhuanZhenJiGou = table.getTRANSFER_REGION();
            try {
                bean.XiaCiSuiFangRiQi = TimeUtils.millis2String(
                        table.getNEXT_VISIT_DATE().getTime(), "yyyy-MM-dd");
            } catch (Exception e) {
                e.printStackTrace();
            }

            bean.SuiFangDoctorName = table.getINPUT_MAN();
            //没有随访类型
//            bean.SuiFangLeiXing = FormatUtils.parseInt(table.getVISIT_WAY());
            bean.SuiFangFangShi = parseInt(table.getVISIT_WAY());
//            bean.FJHID = table.getID();

            bean.FJHZhiLiaoYueXu = parseInt(table.getTREAT_MONTH());
            bean.FJHLouFuYaoCiShu = parseInt(table.getDRUG_TIME());
            bean.FJHYaoWuBuLiangFanYing = parseInt(table.getDRUG_EFFECTS());
            bean.FJHYaoWuBuLiangFanYingMiaoShu = parseString(table.getEFFECTS_STATE());
            bean.FJHBingFaZheng = parseInt(table.getCOMPLICATION());
            bean.FJHBingFaZhengMiaoShu = parseString(table.getCOMPLICATION_STATE());
            bean.FJHLiangZhouNeiSuiFangJieGuo = parseString(table.getTRANSFER_RESULT());
            bean.FJHChuLiYiJian = parseString(table.getADVICE());
            try {
                bean.FJHTingZhiZhiLiaoShiJian = TimeUtils.millis2String(
                        table.getSTOP_TIME().getTime(), "yyyy-MM-dd");
            } catch (Exception e) {
                e.printStackTrace();
            }
            bean.FJHTingZhiZhiLiaoYuanYin = parseString(table.getSTOP_REASON());
            bean.FJHYingFang = parseString(table.getVIEW_NUMBER());
            bean.FJHShiFang = parseString(table.getVIEW_TRUE_NUMBER());
            bean.FJHYingFuYao = parseString(table.getDRUG_NUMBER());
            bean.FJHShiFuYao = parseString(table.getDRUG_TRUE_NUMBER());
            bean.FJHFuYaoLv = parseString(table.getDRUG_RATE());
            bean.FJHPingGuYiShengQianMing = parseString(table.getDOCTOR_SIGN());
            bean.FJHZhengZhuangJiTiZheng = formatAskSymptom(table.getSYMPTOM(),listZZs);
            bean.FJHZhengZhuangJiTiZhengQiTa = table.getSYMPTOM_OTHER();

            List<CD_TUBERCULOSIS_BASEINFO> baseinfos = NovaApplication.fdbmanger.findAllByWhere(CD_TUBERCULOSIS_BASEINFO.class,
                    "CARDID='" + table.getCARDID() + "'");
            if (baseinfos != null && baseinfos.size() > 0) {
                bean.FJHHuanZheLeiXing = parseInt(baseinfos.get(0).getTUBER_TYPE());
                bean.FJHTanJunQingKuang = parseInt(baseinfos.get(0).getTUBER_TJQK());
                bean.FJHNaiYaoQingKuang = parseInt(baseinfos.get(0).getTUBER_NYQK());
//                bean.FJHZhengZhuangJiTiZheng = formatAskSymptom(baseinfos.get(0).getTUBER_ZZTZ(),listZZs);
//                bean.FJHZhengZhuangJiTiZhengQiTa = baseinfos.get(0).getTUBER_ZZQT();
                bean.FJHHuaLiaoFangAn = parseString(baseinfos.get(0).getTUBER_HLFA());
                bean.FJHYongFa = parseInt(baseinfos.get(0).getTUBER_YF());
                bean.FJHYaoPinJiXing = parseString(baseinfos.get(0).getTUBER_YPJX());
                bean.FJHDuDaoRenYuan = parseInt(baseinfos.get(0).getTUBER_DDRYXZ());
                bean.FJHDanDuJvShi = parseInt(baseinfos.get(0).getTUBER_DDJS());
                bean.FJHTongFengQingKuang = parseInt(baseinfos.get(0).getTUBER_TFQK());
                bean.FJHXiYan = parseInt(baseinfos.get(0).getSMOKE());
                bean.FJHMuBiaoXiYan = parseInt(baseinfos.get(0).getTARGET_SMOKE());
                bean.FJHYinJiu = parseInt(baseinfos.get(0).getDRINK());
                bean.FJHMuBiaoYinJiu = parseInt(baseinfos.get(0).getTARGET_DRINK());
                bean.FJHQvYaoDiDian = parseString(baseinfos.get(0).getTUBER_QYDD());
                bean.FJHQvYaoShiJian = parseString(baseinfos.get(0).getTUBER_QYSJ());
                bean.FJHFuYaoJiLuKa = parseInt(baseinfos.get(0).getTUBER_JLK());
                bean.FJHFuYaoFangFa = parseInt(baseinfos.get(0).getTUBER_FYFF());
                bean.FJHZhiLiaoLiaoCheng = parseInt(baseinfos.get(0).getTUBER_ZLLC());
                bean.FJHBuGuiLvFuYaoWeiHai = parseInt(baseinfos.get(0).getTUBER_WH());
                bean.FJHBuLiangFanYing = parseInt(baseinfos.get(0).getTUBER_BLFY());
                bean.FJHFuZhenChaTan = parseInt(baseinfos.get(0).getTUBER_FZCT());
                bean.FJHWaiChuJianChiFuYao = parseInt(baseinfos.get(0).getTUBER_RHFY());
                bean.FJHZhuYiShiXiang = parseInt(baseinfos.get(0).getTUBER_SHXG());
                bean.FJHMiQieJieChuZheJianCha = parseInt(baseinfos.get(0).getTUBER_JCZJC());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return bean;
    }
}
